package com.mdp.sys.ctrl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mdp.core.entity.Result;
import com.mdp.core.err.BizException;
import com.mdp.core.query.QueryTools;
import com.mdp.core.utils.NumberUtil;
import com.mdp.swagger.ApiEntityParams;
import com.mdp.sys.entity.UserTpa;
import com.mdp.sys.service.UserTpaService;
import io.swagger.annotations.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
 * url编制采用rest风格,如对ADMIN.sys_user_tpa 第三方系统向我方开放的用户列表的操作有增删改查,对应的url分别为:<br>
 *  新增: sys/userTpa/add <br>
 *  查询: sys/userTpa/list<br>
 *  模糊查询: sys/userTpa/listKey<br>
 *  修改: sys/userTpa/edit <br>
 *  删除: sys/userTpa/del<br>
 *  批量删除: sys/userTpa/batchDel<br>
 * 组织 com.qqkj  顶级模块 mdp 大模块 sys 小模块 <br>
 * 实体 UserTpa 表 ADMIN.sys_user_tpa 当前主键(包括多主键): id; 
 ***/
@RestController("mdp.sys.userTpaController")
@RequestMapping(value="/**/sys/userTpa")
@Api(tags={"第三方系统向我方开放的用户列表操作接口"})
public class UserTpaController {
	
	static Log logger=LogFactory.getLog(UserTpaController.class);
	
	@Autowired
	private UserTpaService userTpaService;
	 

	
	@ApiOperation( value = "查询第三方系统向我方开放的用户列表信息列表",notes="listUserTpa,条件之间是 and关系,模糊查询写法如 {studentName:'%才哥%'}")
	@ApiEntityParams(UserTpa.class)
	@ApiResponses({
		@ApiResponse(code = 200,response= UserTpa.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'错误码'},pageInfo:{total:总记录数},data:[数据对象1,数据对象2,...]}")
	})
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public Result listUserTpa(@ApiIgnore @RequestParam Map<String,Object> params){
		 
		IPage page=QueryTools.initPage(params);
		QueryWrapper<UserTpa> qw= QueryTools.initQueryWrapper(UserTpa.class,params);
		List<Map<String,Object>>	userTpaList = userTpaService.selectListMapByWhere(page,qw,params);
		
		return Result.ok().setData(userTpaList).setTotal(page.getTotal());
		
		
	}
	
	@RequestMapping(value="/selectByUserTpa",method=RequestMethod.GET)
	public Result selectByUserTpa( @ApiIgnore @RequestParam Map<String,Object> userTpa){

		List<Map<String,Object>>	userTpaList = userTpaService.selectByUserTpa(userTpa);	//列出UserTpa列表
		
		return Result.ok().setData(userTpaList).setTotal(NumberUtil.getLong(userTpaList.size()));
		
		
	}
	
	@RequestMapping(value="/selectByMemMember",method=RequestMethod.GET)
	public Result selectByMemMember(  @ApiIgnore @RequestParam Map<String,Object>  menMenber){

		List<Map<String,Object>>	menMenberList = userTpaService.selectByMemMember(menMenber);	//列出UserTpa列表
		
		return Result.ok().setData(menMenberList);
		
	}
	
	@RequestMapping(value="/addSubacctAddForm",method=RequestMethod.POST)
	public Result subacctAddForm(@RequestBody Map<String,Object> map) {
		
		
		try{
			userTpaService.addSubacctAddForm(map);
			return Result.ok();
		}catch (BizException e) { 
			logger.error("执行异常",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("执行异常",e);
			return Result.error(e);
		}  
	}
	/**
	@ApiOperation( value = "新增一条第三方系统向我方开放的用户列表信息",notes="addUserTpa,主键如果为空，后台自动生成")
	@ApiResponses({
		@ApiResponse(code = 200,response=UserTpa.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
	}) 
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public Result addUserTpa(@RequestBody UserTpa userTpa) {
		
		
		try{
			if(StringUtils.isEmpty(userTpa.getId())) {
				userTpa.setId(userTpaService.createKey("id"));
			}else{
				 UserTpa userTpaQuery = new  UserTpa(userTpa.getId());
				if(userTpaService.countByWhere(userTpaQuery)>0){
					return Result.error("id-exists","编号重复，请修改编号再提交");
				}
			}
			userTpaService.insert(userTpa);
			return Result.ok().setData(userTpa);
		}catch (BizException e) { 
			logger.error("执行异常",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("执行异常",e);
			return Result.error(e);
		}  
	}
	*/
	
	/** */
	@ApiOperation( value = "删除一条第三方系统向我方开放的用户列表信息",notes="delUserTpa,仅需要上传主键字段")
	@ApiResponses({
		@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}")
	}) 
	@RequestMapping(value="/del",method=RequestMethod.POST)
	public Result delUserTpa(@RequestBody UserTpa userTpa){
		
		
		try{
			userTpaService.deleteByPk(userTpa);
			return Result.ok();
		}catch (BizException e) { 
			logger.error("执行异常",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("执行异常",e);
			return Result.error(e);
		}  
	}
	 
	
	/**
	@ApiOperation( value = "根据主键修改一条第三方系统向我方开放的用户列表信息",notes="editUserTpa")
	@ApiResponses({
		@ApiResponse(code = 200,response=UserTpa.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
	}) 
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public Result editUserTpa(@RequestBody UserTpa userTpa) {
		
		
		try{
			userTpaService.updateByPk(userTpa);
			return Result.ok().setData(userTpa);
		}catch (BizException e) { 
			logger.error("执行异常",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("执行异常",e);
			return Result.error(e);
		}  
	}
	*/
	

	
	/**
	@ApiOperation( value = "根据主键列表批量删除第三方系统向我方开放的用户列表信息",notes="batchDelUserTpa,仅需要上传主键字段")
	@ApiResponses({
		@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}")
	}) 
	@RequestMapping(value="/batchDel",method=RequestMethod.POST)
	public Result batchDelUserTpa(@RequestBody List<UserTpa> userTpas) {
		
		 
		try{ 
			userTpaService.batchDelete(userTpas);
		}catch (BizException e) { 
			logger.error("执行异常",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("执行异常",e);
			return Result.error(e);
		}  
	} 
	*/
}
